package com.most.auth.controller;

import com.most.api.GoodsClient;
import com.most.api.UserVO;
import com.most.auth.dto.User;
import com.most.auth.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sysUser")
@RefreshScope
@Api("用户模块")
public class UserController {
    @Value("${user:#{null}}")
    private String username;

    @GetMapping("getUser")
    @ResponseBody
    public String getUser() {
        return username;
    }

    @Autowired
    GoodsClient goodsClient;
    @Autowired
    UserService userserive;

    @GetMapping("getGoods")
    @ResponseBody
    public String getGoods() {
        return goodsClient.getGoods();
    }
    @GetMapping("addUser")
    @ResponseBody
    public User addUser() {
        User user = new User();
        user.setUsername("test1");
        user.setPassword("123456");
        userserive.setPassword(user);
        boolean save = userserive.save(user);
        return user;
    }
    @GetMapping("list")
    @ResponseBody
    @ApiOperation("获取用户列表")
    public List<User> list() {
        List<User> list = userserive.list();
        return list;
    }
    @GetMapping("getPermissionsById")
    @ResponseBody
    @ApiOperation("获取用户列表")
    public List<String> getPermissionsById(Long id) {
        List<String> list = userserive.getPermissionsById(id);
        return list;
    }
    @GetMapping("findOneByUserName")
    @ResponseBody
    @ApiOperation("获取用户列表")
    public UserVO findOneByUserName(@RequestParam("username") String username) {
        UserVO user = userserive.findOneByUserName(username);
        return user;
    }
}